package org.dtrd.modules.service.entity.bean;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.dtrd.common.util.StringUtil;
import org.dtrd.config.pay.OrderUtil;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.service.entity.po.DtrdEntRdServicePackage;

import java.util.List;

/**
 * @author qr
 * @date 2021/12/16 13:28
 */
@ApiModel("服务包数据")
@Data
@NoArgsConstructor
public class ServicePackage {

    @ApiModelProperty("服务包id")
    private Integer packageId;

    @ApiModelProperty("服务包名称")
    private String packageName;

    @ApiModelProperty("服务包描述")
    private String packageDesc;

    @ApiModelProperty("服务包周期")
    private String packageServicePeriod;

    @ApiModelProperty("服务包价格")
    private String price;

    @ApiModelProperty("服务包价格-折扣价")
    private String discountPriceStr;

    @ApiModelProperty("服务包价格-折扣价")
    private Integer discountPrice;

    @ApiModelProperty(value = "服务包详情", notes = "是一张长海报")
    private String packageDetail;

    @ApiModelProperty(value = "轮播图")
    private String[] imgUrl;

    @ApiModelProperty(value = "售卖状态")
    private Boolean saleState = false;

    @ApiModelProperty(value = "管理成效")
    private List<ManageEffect> manageEffect;

    @ApiModelProperty(value = "服务包规格")
    private List<PackageSpecs> packageSpecs;

    public ServicePackage(DtrdEntRdServicePackage po) {
        this.packageId = po.getDataId();
        this.packageName = po.getPackageName();
        this.packageDesc = po.getPackageDesc();
        // 设置服务周期
        Integer periodUnit = po.getPeriodUnit();
        Integer period = po.getPackageServicePeriod();
        Constant.PeriodUnit unit = Constant.PeriodUnit.valueOf(periodUnit);
        packageServicePeriod = period + (unit != null ? unit.getName() : "");
        price = wrappPrice(po.getPackagePrice());
        discountPriceStr = wrappPrice(po.getPackageDiscount());
        discountPrice = po.getPackageDiscount();
        if (po.getPackageSlideshow() != null) {
            imgUrl = po.getPackageSlideshow().split(",");
        }
        packageDetail = po.getPackageDetail();
        if (StringUtils.isNotEmpty(po.getManageEffect())) {
            manageEffect = JSON.parseArray(po.getManageEffect(), ManageEffect.class);
        }
    }

    private String wrappPrice(Integer sourcePrice) {
        if (sourcePrice != null) {
            return OrderUtil.changeF2Y((long) sourcePrice);
        }
        return "0";
    }


}
